package bw.com.controller;

import bw.com.service.EduService;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService eduService;
    @RequestMapping("/shuZi")
   public Object shuZi(){
        List<Map> list = eduService.shuZi();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("final"));
        return  jsonObject;
    }
    @RequestMapping("/lun")
    public Object lun(String total){
        List<Map> list = eduService.lun(total);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","分组织");
        jsonObject1.put("id","subsys");
        colArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","部门");
        jsonObject2.put("id","module");
        colArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","业务组");
        jsonObject3.put("id","business");
        colArray.add(jsonObject3);

        JSONObject jsonObject4 = new JSONObject();
        jsonObject4.put("name","姓名");
        jsonObject4.put("id","name");
        colArray.add(jsonObject4);

        JSONObject jsonObject5 = new JSONObject();
        jsonObject5.put("name","销售额");
        jsonObject5.put("id","value");
        colArray.add(jsonObject5);

        dataObject.put("columns",colArray);

        JSONArray rowArray = new JSONArray();
        for (Map map : list) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("name"));
            rowObject.put("module",map.get("Uid"));
            rowObject.put("business",map.get("zb"));
            rowObject.put("name",map.get("avgzb"));
            rowArray.add(rowObject);
        }

       dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return  jsonObject;
    }
    @RequestMapping("/biao")
    public Object biao(String total){
        List<Map> list = eduService.lun(total);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","分组织");
        jsonObject1.put("id","subsys");
        colArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","部门");
        jsonObject2.put("id","module");
        colArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","业务组");
        jsonObject3.put("id","business");
        colArray.add(jsonObject3);

        JSONObject jsonObject4 = new JSONObject();
        jsonObject4.put("name","姓名");
        jsonObject4.put("id","name");
        colArray.add(jsonObject4);

        JSONObject jsonObject5 = new JSONObject();
        jsonObject5.put("name","销售额");
        jsonObject5.put("id","value");
        colArray.add(jsonObject5);

        dataObject.put("columns",colArray);

        JSONArray rowArray = new JSONArray();
        for (Map map : list) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("name"));
            rowObject.put("module",map.get("Uid"));
            rowObject.put("business",map.get("zb"));
            rowObject.put("name",map.get("avgzb"));
            rowArray.add(rowObject);
        }

        dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return  jsonObject;
    }
    @RequestMapping("/shen")
    public Object shen( ){
        List<Map> list = eduService.shen();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("final"));
            mapArray.add(mapObject);
        }
        dataObject.put("mapData",mapArray);
        jsonObject.put("data",dataObject);
        return  jsonObject;
    }
    @RequestMapping("/zhu")
    public Object zhu( ){
        List<Map> list = eduService.zhu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();
        for (Map map : list) {
            xArray.add(map.get("name"));
        }
        dataObject.put("categories",xArray);
        JSONArray yArray = new JSONArray();
        JSONObject yObject = new JSONObject();
        yObject.put("name","上周");
        JSONArray dataArray = new JSONArray();
        yObject.put("data",dataArray);
        for (Map map : list) {
            dataArray.add(map.get("Uid"));
        }
        yArray.add(yObject);
        dataObject.put("series",yArray);
        jsonObject.put("data",dataObject);
        return  jsonObject;
    }
}
